package com.usian.controller;

import com.usian.pojo.Course;
import com.usian.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @RequestMapping("/toCourse")
    public String toCourse(){
        return "add";
    }

    @RequestMapping("/add")
    public String add( Course course){
        courseService.add(course);
        return "redirect:findAll";
    }

    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Course> list=courseService.findList();
        model.addAttribute("list",list);
        return "index";
    }

    @RequestMapping("/del")
    public String del(Integer id){
        courseService.del(id);
        return "redirect:findAll";
    }

    @RequestMapping("updates")
    public String updates(Model model,Integer id){
        Course course=courseService.updates(id);
        model.addAttribute("course",course);
        return "update";
    }

    @RequestMapping("update")
    public String update(Course course){
        courseService.update(course);
        return "redirect:findAll";
    }
}
